﻿using System;
using PTiRouZ.Net.SilverLight.Api;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Runtime.Serialization;

namespace PTiRouZ.Net.SilverLight.Api.HelloTipi
{

    /*{"favorited":"null","text":"\u00c0 lire sur le blog d'Hellotipi: <br \/>http:\/\/www.hellotipi.com\/blog\/envoyer-des-photos-sur-son-site-hellotipi-via-picasa\/","in_reply_to_user_id":"null","created_at":"Wed May 19 16:49:31 +0200 2010","created_at_iso8601":"2010-05-19T16:49:31+02:00","truncated":"false","source":"http:\/\/rousee.hellotipi.com","id":"445682","user":{"id":"3651","name":"Christophe Rous\u00e9e","screen_name":"ptirouz#rousee","location":"","description":"","profile_image_url":"http:\/\/img.hellotipi.com\/gallery\/user\/3651_56301b36a7.jpg","url":"http:\/\/rousee.hellotipi.com\/?page=profil&action=view_one&login=ptirouz","protected":"false","followers_count":0},"site":{"name":"rousee","title":null}}*/
    /// <summary>Objet du résultat d'une requête destroy</summary>
    /// <see cref="friends_timeline"></see>
    [DataContract]
    public class destroy
    {
        /// <summary>non utilisé</summary>
        //[DataMember]
        //public bool favorited { get; set; }

        /// <summary>texte du message</summary>
        [DataMember]
        public string text { get; set; }

        /// <summary>non utilisé</summary>
        //[DataMember]
        //public int in_reply_to_user_id { get; set; }

        /// <summary>date du message au format suivant : Tue Sep 16 11:38:39 +0200 2008 </summary>
        /// <remarks>en PHP : date(D M j H:i:s O Y</remarks>
        [DataMember]
        public string created_at { get; set; }

        /// <summary>date du message au format suivant : 2010-05-11T11:54:22+02:00 </summary>
        [DataMember]
        public string created_at_iso8601 { get; set; }
       
        /// <summary>non utilisé</summary>
        //[DataMember]
        //public bool truncated { get; set; }

        /// <summary>url du site de famille</summary>
        [DataMember]
        public string source { get; set; }

        /// <summary>id du message</summary>
        [DataMember]
        public int id { get; set; }

        /// <summary>identifiant du site</summary>        
        [DataMember]
        public user user { get; set; }

        /// <summary>titre du site</summary>        
        [DataMember]
        public site site { get; set; }
    }

    public delegate void DestroyEventHandler(object sender, DestroyEventArgs e);
    public class DestroyEventArgs : EventArgs
    {
        public DestroyEventArgs(destroy d)
        {
            _result = d;
        }

        private destroy _result;
        public destroy result { get { return _result; } }
    }

    public partial class apitxt : api
    {

        public event DestroyEventHandler DestroyCompleted;

        #region destroy
        /// <summary>destroy</summary>
        /// <c>http://apitxt.hellotipi.com/statuses/destroy/id.format</c>
        /// <remarks>id requis</remarks>
        /// <param name="id">l’ID du message à effacer</param>
        /// <returns>Renvoie une erreur 404 si le message n’existe pas, ou le message effacé en cas de succès dans un <typeparamref name="destroy"/></returns>
        public void Destroy(int id)
        {

            base.APICallCompleted += new APICallCompletedEventHandler(DestroyCallCompleted);

            //var querystring = new List<KeyValuePair<string, string>> {"id", id.ToString() };

            PostUrlApi(String.Format("statuses/destroy/{0}", id));
        }

        void DestroyCallCompleted(object sender, ApiOpenReadCompletedEventArgs e)
        {
            try
            {
                if (e.Result != null)
                    DestroyCompleted.Invoke(sender, new DestroyEventArgs(serializeTools.Deserialize<destroy>(e.Result)));
            }
            finally
            {
                base.APICallCompleted -= new APICallCompletedEventHandler(DestroyCallCompleted);
            }
        }

        #endregion
    }

}

